package middle;

public class Solution_396 {

    public static void main(String[] args) {
        Solution_396 model = new Solution_396();
        System.out.println(model.maxRotateFunction(new int[]{4,3,2,6}));
        System.out.println(model.maxRotateFunction(new int[]{4}));
    }

    public int maxRotateFunction(int[] nums) {
        int base = 0, index = nums.length - 1;
        for (int num : nums) {
            base += num;
        }
        int sum = 0, max = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            sum += (nums[i] * i);
        }
        do {
//            System.out.println(sum);
            if (sum > max) {
                max = sum;
            }
            sum = sum + base - nums[index] * nums.length;
            index--;
        } while (index >= 0);
        return max;
    }
}
